<?php
/*	Created by Alexander Alexandrov aka SS
			hazg@mail.ru				*/
define('SSLIB_Image', TRUE);
//TODO: 
class Image
{
	private static $magickpaths = array('/usr/local/bin/','/usr/bin/');
	static function Convert($path, $outpath, $totype = "jpg")
	{
		return true;
	}
	static function Thumb($path,$outpath,$new_w,$new_h, $stretch = false, $smooth = true)
	{
		$i = null;
		$convert = Image::findMagick('convert');
		if(!$convert) throw new Err(__T('not found').': convert');
		
		exec("$convert $path -resize {$new_w}x{$new_h} $outpath", $out, $err);
		if($err){throw new Err();}
		
		return false;
	}
	static function Watermark($src, $wtm, $dest = "", $gravity = "center")
	{
		if(empty($dest)) $dest = $src;
		
		$composite = Image::findMagick('composite');
		if(!$composite) throw new Err(__T('not found').': composite');
		
		exec("$composite -gravity $gravity $wtm $src $dest", $arr);
	}
	private static function findMagick($prog)
	{
		foreach(Image::$magickpaths as $path){if(file_exists($path.$prog)){return $path.$prog;}}
		return FALSE;
	}
}
?>